import jsonschema


class EmpDataSch():
    @classmethod
    def add_emp_sch(self, data):
        # 添加员工数据测试规则
        schema = {
            "type": "object",
            "properties": {
                "desc": {"type": "string"},
                "req_data": {
                    "type": "object",
                    "properties": {
                        "username": {"type": "string"},
                        "mobile": {"type": "string", "pattern": "^1[3,5,7,8][0-9]{9}$"},
                        "workNumber": {"type": "string"}
                    }
                },
                "stauts_code": {"const": 200, "type": "integer"},
                "success": {"type": "boolean"},
                "code": {"type": "integer"},
                "message": {"type": "string"}
            },
            "required": ["desc", "req_data", "stauts_code", "success", "code", "message"]
        }
        for i in range(len(data)):
            jsonschema.validate(schema=schema, instance=data[i])

    @classmethod
    def get_emp_sch(self, data):
        # 查询员工数据测试规则
        schema = {
            "type": "object",
            "properties": {
                "desc": {"type": "string"},
                "id_drit": {
                    "type": "object",
                    "properties": {
                        "id_emp": {"type": "string"}
                    },
                    "required": ["id_emp"]
                },
                "stauts_code": {"const": 200, "type": "integer"},
                "success": {"type": "boolean"},
                "code": {"type": "integer"},
                "message": {"type": "string"}
            },
            "required": ["desc", "id_drit", "stauts_code", "success", "code", "message"]
        }
        for i in range(len(data)):
            jsonschema.validate(schema=schema, instance=data[i])

    @classmethod
    def put_emp_sch(self, data):
        # 修改员工数据测试规则
        schema = {
            "type": "object",
            "properties": {
                "desc": {"type": "string"},
                "id_drit": {
                    "type": "object",
                    "properties": {
                        "id_emp": {"type": "string"}}
                },
                "modify_data": {
                    "type": "object",
                    "properties": {
                        "username": {"type": "string"},
                        "password": {"type": "string"},
                        "departmentId": {"type": "string"},
                        "departmentName": {"type": "string"}
                    }
                },
                "stauts_code": {"const": 200, "type": "integer"},
                "success": {"type": "boolean"},
                "code": {"type": "integer"},
                "message": {"type": "string"}
            },
            "required": ["desc", "id_drit", "modify_data", "stauts_code", "success", "code", "message"]
        }
        for i in range(len(data)):
            jsonschema.validate(schema=schema, instance=data[i])

    @classmethod
    def delet_emp_sch(self, data):
        # 删除员工测试数据规则
        schema = {
            "type": "object",
            "properties": {
                "desc": {"type": "string"},
                "id_drit": {
                    "type": "object",
                    "properties": {
                        "id_emp": {"type": "string"}
                    },
                    "required": ["id_emp"]
                },
                "stauts_code": {"const": 200, "type": "integer"},
                "success": {"type": "boolean"},
                "code": {"type": "integer"},
                "message": {"type": "string"}
            },
            "required": ["desc", "id_drit", "stauts_code", "success", "code", "message"]
        }
        for i in range(len(data)):
            jsonschema.validate(schema=schema, instance=data[i])

    if __name__ == '__main__':
        path = "../data/ihrm_add_emp.json"
        data = read_json_data(path)
        add_emp_sch(data)
